package cn.tianyigps.tianyigpsynclean.customer;

import cn.tianyigps.tianyigpskafka.task.customer.NewCustomer;
import cn.tianyigps.tianyigpspublic.param.bo.Task;
import cn.tianyigps.tianyigpspublic.param.constant.EquipmentReceiveConstant;
import cn.tianyigps.tianyigpsynclean.hanlder.CleanHanlder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.Map;


/**
 * @Author: WEI.YUAN
 * @Descirption:数据清洗消费者
 * @Date: 2019/4/24_15:34
 */
@Component
@Slf4j
public class DataCleanCustomer extends NewCustomer {
    @Autowired
    CleanHanlder cleanHanlder;

    @Override
    public boolean checkTask(Task task) {
        Map<String, String> params = task.getParams();
        if(CollectionUtils.isEmpty(params)){
            log.error("轨迹数据不能为空");
            return false;
        }
        if (StringUtils.isEmpty(params.get(EquipmentReceiveConstant.UpTime))) {
            log.error("上报时间uptime不能为空");
            return false;
        }
        return true;
    }

    @Override
    public void consume(Task task) {
        cleanHanlder.dataClean(task);
    }

}
